//
//  EFTimeView.m
//  EnjogFood
//
//  Created by 王芳 on 17/5/1.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFTimeView.h"
#import "EFSaleListItem.h"

@interface EFTimeView ()
@property (strong, nonatomic) UIImageView *selectedImageV;
@property (assign, nonatomic) BOOL isSelected;
@end

@implementation EFTimeView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame item:(EFSaleListItem *)item{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
        [self refreshUI:item];
    }
    return self;
}

- (void)initUI{
    [self addSubview:self.selectedImageV];
    [self addSubview:self.dateLabel];
    [self addSubview:self.timeLabel];
}

- (void)refreshUI:(EFSaleListItem *)item{
    self.dateLabel.text = item.date;
    [self.dateLabel sizeToFit];
    self.dateLabel.top= 3;
    self.dateLabel.left = (self.width - self.dateLabel.width)/2;
    
    self.timeLabel.text = item.startTime;
    [self.timeLabel sizeToFit];
    self.timeLabel.top = self.dateLabel.bottom + 5;
    self.timeLabel.left = (self.width - self.timeLabel.width)/2;
    
    if (item.isSelected == YES) {
        self.selectedImageV.hidden = false;
        self.dateLabel.textColor = [UIColor whiteColor];
        self.timeLabel.textColor = [UIColor whiteColor];
    }else{
        self.selectedImageV.hidden = true;
        self.dateLabel.textColor = kBlack999;
        self.timeLabel.textColor = kBlack999;
    }
}

- (UILabel *)dateLabel{
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.font = [UIFont systemFontOfSize:13];
        _dateLabel.textColor = [UIColor whiteColor];
    }
    return _dateLabel;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.font = [UIFont boldSystemFontOfSize:17];
        _timeLabel.textColor = [UIColor whiteColor];
    }
    return _timeLabel;
}

- (UIImageView *)selectedImageV{
    if (!_selectedImageV) {
        _selectedImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 75, 51)];
        _selectedImageV.image = IMG(@"Spike_menu_button_bg_home_selected");
        _selectedImageV.hidden = YES;
    }
    return _selectedImageV;
}

@end
